<?php
define('SCR','post');
require_once('global.php');
require_once(R_P.'require/forum.php');
include_once(D_P.'data/bbscache/cache_post.php');
/**
* 版块缓冲文件
*/
empty($fid) && Showmsg('undefined_action');
//获取非分类信息
$foruminfo = $db->get_one("SELECT * FROM pw_forums f LEFT JOIN pw_forumsextra fe USING(fid) WHERE f.fid=".pwEscape($fid)." AND type<>'category'");
!$foruminfo && Showmsg('data_error');


//array 
$forumset  = unserialize($foruminfo['forumset']);
//
$creditset = $foruminfo['creditset'];

//权限
wind_forumcheck($foruminfo);

/*
* 获取管理权限
*/
$isGM = CkInArray($windid,$manager);
$isBM = admincheck($foruminfo['forumadmin'],$foruminfo['fupadmin'],$windid);


$admincheck = ($isGM || $isBM) ? 1 : 0;

if (!$admincheck && !$foruminfo['allowvisit']) {
	//限制
	forum_creditcheck();
}

if ($forumset['allowtime'] && !$isGM && !allowcheck($forumset['allowtime'],$t['hours'],'') && !pwRights($isBM,'allowtime')) {
	Showmsg('forum_allowtime');
}


list($uploadcredit,$uploadmoney,,) = explode("\t",$forumset['uploadset']);

InitGP(array('action','special','article','pid','p_type','page'));
$replacedb = array();
$special   = (int)$special;
$secondurl = "thread.php?fid=$fid";
!$action && $action = "new";


if ($action == 'new' && !($foruminfo['allowtype'] & pow(2,$special))) {
	
	if (empty($special) && $foruminfo['allowtype'] > 0) {
		$special = (int)log($foruminfo['allowtype'],2);
	} else {
		//类型
		Showmsg('post_allowtype');
	}
}


list($db_openpost,$db_poststart,$db_postend) = explode("\t",$db_openpost);


//由于工作力度与时间原因, 站点开放发帖时间为 0:00 点到 0:00 点 !
if ($db_openpost == 1 && $groupid != 3 && $groupid != 4) {
	//fly a $t variable
	if ($db_poststart < $db_postend && ($t['hours'] < $db_poststart || $t['hours'] >= $db_postend)) {
		Showmsg('post_openpost');
	} elseif ($db_poststart > $db_postend && ($t['hours'] < $db_poststart && $t['hours'] >= $db_postend)) {
		Showmsg('post_openpost');
	}
}
/**
* 禁止受限制用户发言
*/
if ($groupid == 6 || getstatus($winddb['userstatus'],1)) {
	$pwSQL = '';
	$flag  = 0;
	$bandb = $delban = array();
	$query = $db->query("SELECT * FROM pw_banuser WHERE uid=".pwEscape($winduid));
	while ($rt = $db->fetch_array($query)) {
		if ($rt['type'] == 1 && $timestamp - $rt['startdate'] > $rt['days']*86400) {
			$delban[] = $rt['id'];
		} elseif ($rt['fid'] == 0 || $rt['fid'] == $fid) {
			$bandb[$rt['fid']] = $rt;
		} else {
			$flag = 1;
		}
	}
	//取消禁止用户
	$delban && $db->update('DELETE FROM pw_banuser WHERE id IN('.pwImplode($delban).')');
	
	($groupid == 6 && !isset($bandb[0])) && $pwSQL .= "groupid='-1',";
	
	if (getstatus($winddb['userstatus'],1) && !isset($bandb[$fid]) && !$flag) {
		$pwSQL .= 'userstatus=userstatus&(~1),';
	}
	if ($pwSQL = rtrim($pwSQL,',')) {
		$db->update("UPDATE pw_members SET $pwSQL WHERE uid=".pwEscape($winduid));
	}
	if ($bandb) {
		$bandb = current($bandb);
		if ($bandb['type'] == 1) {
			//开始  结束时间
			$s_date = get_date($bandb['startdate']);
			$e_date = $bandb['startdate'] + $bandb['days']*86400;
			$e_date = get_date($e_date);
			Showmsg('ban_info1');
		} else {
			if ($bandb['type'] == 3) {
				Cookie('force',$winduid);
				Showmsg('ban_info3');
			} else {
				Showmsg('ban_info2');
			}
		}
	}
}

//是否禁用
if (GetCookie('force') && $winduid != GetCookie('force')) {
	$force = GetCookie('force');
	$bandb = $db->get_one("SELECT type FROM pw_banuser WHERE uid=".pwEscape($force)." AND fid='0'");
	if ($bandb['type'] == 3) {
		Showmsg('ban_info3');
	} else {
		Cookie('force','',0);
	}
}
/**
* 需要验证用户只有通过管理员验证后才能发帖
*/
if ($groupid == '7') {
	Showmsg('post_check');
}

/*
* 新注册会员发帖时间限制
*/
if ($db_postallowtime && $timestamp-$winddb['regdate']<$db_postallowtime*60) {
	Showmsg('post_newrg_limit');
}
$userlastptime = $groupid != 'guest' ?  $winddb['lastpost'] : GetCookie('userlastptime');


/**
* 灌水预防
*/
$tdtime  >= $winddb['lastpost'] && $winddb['todaypost'] = 0;
$montime >= $winddb['lastpost'] && $winddb['monthpost'] = 0;
if ($_G['postlimit'] && $winddb['todaypost'] >= $_G['postlimit']) {
	Showmsg('post_gp_limit');
}

if ($action!="modify" && !$isGM && $_G['postpertime'] && $timestamp>=$userlastptime && $timestamp-$userlastptime<=$_G['postpertime'] && !pwRights($isBM,'postpers')) {
	Showmsg('post_limit');
}

list(,,$postq)  = explode("\t",$db_qcheck);
$_G['uploadtype'] && $db_uploadfiletype = $_G['uploadtype'];
$db_uploadfiletype = !empty($db_uploadfiletype) ? unserialize($db_uploadfiletype) : array();

empty($db_sellset['type']) && $db_sellset['type'] = array('money');
empty($db_enhideset['type']) && $db_enhideset['type'] = array('rvrc');
$htmlsell = ($foruminfo['allowsell'] && $_G['allowsell']) ? '' : 'disabled';
$htmlhide = ($forumset['allowencode'] && $_G['allowencode']) ? '' : 'disabled';


if (empty($_POST['step'])) {
	
	require_once(R_P.'require/credit.php');
	$editor = getstatus($winddb['userstatus'],11) ? 'wysiwyg' : 'textmode';
	!is_numeric($db_attachnum) && $db_attachnum = 1;
	$htmlpost   = $htmlatt = ($foruminfo['allowhide'] && $_G['allowhidden']) ? '' : 'disabled';
	$ifanonymous= ($isGM || $forumset['anonymous'] && $_G['anonymous']) ? '' : 'disabled';
	$groupid   == 'guest' && $userrvrc = 0;
	$atc_title  = $atc_content = $ifmailck = $selltype = $enhidetype = $alltype = '';
	$uploadfiletype = $uploadfilesize = ' ';
	
	foreach ($db_uploadfiletype as $key => $value) {
		$uploadfiletype .= $key.' ';
		$uploadfilesize .= $key.':'.$value.'KB; ';
	}
	foreach ($credit->cType as $key => $value) {
		$alltype .= "<option value=\"$key\">".$value."</option>";
	}
	
	//array ( 'price' => '', 'income' => '', 'type' => array ( 0 => 'money', ), )
	foreach ($db_sellset['type'] as $key => $value) {
		$selltype .= "<option value=\"$value\">".$credit->cType[$value]."</option>";
	}
	foreach ($db_enhideset['type'] as $key => $value) {
		$enhidetype .= "<option value=\"$value\">".$credit->cType[$value]."</option>";
	}
	/**
	* 标题表情
	*/
	$icondb = array(
		'1'=>'1.gif',	'2'=>'2.gif',
		'3'=>'3.gif',	'4'=>'4.gif',
		'5'=>'5.gif',	'6'=>'6.gif',
		'7'=>'7.gif',	'8'=>'8.gif'
	);
	if ($db_allowupload && $_G['allowupload']) {
		$mutiupload = $db->get_value("SELECT COUNT(*) AS sum FROM pw_attachs WHERE tid=0 AND pid='0' AND uid=" . pwEscape($winduid));
	}
} else {

	PostCheck(1, ($db_gdcheck & 4) && $winddb['postnum'] < $db_postgd, $winddb['postnum'] < $postq);
	!$windid && $windid = 'guest';

	require_once(R_P.'require/bbscode.php');
	require_once(R_P.'require/postfunc.php');
	if (@include(D_P."data/bbscache/wordsfb.php")) {
		foreach ($wordsfb as $key => $value) {
			$banword = (string) stripslashes($key);
			if (strpos($_POST['atc_title'],$banword)!==false) {
				Showmsg('title_wordsfb');
			} elseif (strpos($_POST['atc_content'],$banword)!==false) {
				Showmsg('content_wordsfb');
			} elseif (strpos($_POST['atc_tags'],$banword)!==false) {
				Showmsg("tag_wordsfb");
			}
		}
		foreach ($replace as $key => $value) {
			$banword = (string) stripslashes($key);
			if (strpos($_POST['atc_title'],$banword)!==false) {
				Showmsg('post_wordsfb');
			} elseif (strpos($_POST['atc_tags'],$banword)!==false) {
				Showmsg("tag_wordsfb");
			}
		}
	}
	$ipfrom = Char_cv(cvipfrom($onlineip));
	$atc_usesign = $_POST['atc_usesign'] ? 1 : 0;
	if ($_G['htmlcode'] && $_POST['atc_html']) {
		$atc_usesign += 2;
	}
	/**
	* 得到父版块id
	*/
	$fatherid = $foruminfo['type']=='sub' ? $foruminfo['fup']:'';
}
//默认动漫表情处理
if ($db_windmagic && ($action == 'new' || ($action == 'modify' && $pid == 'tpc'))) {
	$mDef = '';
	@include_once(D_P."data/bbscache/myshow_default.php");
}
if ($action == "new") {
	require_once(R_P.'require/postnew.php');
} elseif ($action == "reply" || $action == "quote") {
	require_once(R_P.'require/postreply.php');
} elseif ($action == "modify") {
	require_once(R_P.'require/postmodify.php');
} else {
	Showmsg('undefined_action');
}
?>